package net.caixiaomi.info.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import com.sobot.chat.utils.ScreenUtils;

import net.caixiaomi.info.R;

/**
 * Created by mac on 2018/9/14.
 */

public class DividerView extends RelativeLayout{

    private int mDividerColor=R.color.divider;
    private View leftDivider;
    private View rightDivider;
    private View topDivider;
    private View bottomDivider;

    public final static int LEFT_TOP=0;
    public final static int RIGHT=1;
    public final static int BOTTOM=2;
    public final static int LAST_LEFT=3;
    public final static int LEFT_TOP_RIGHT=4;
    public final static int TOP_RIGHT=5;
    public final static int LEFT=6;

    private Context context;

    private View ChildView;

    public DividerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        ChildView=getChildAt(0);
        leftDivider=new View(context);
        LayoutParams leftParams=new LayoutParams(ScreenUtils.dip2px(context,1),LayoutParams.MATCH_PARENT);
        leftDivider.setLayoutParams(leftParams);
        leftDivider.setBackgroundResource(mDividerColor);

        rightDivider=new View(context);
        RelativeLayout.LayoutParams rightParams=new RelativeLayout.LayoutParams(ScreenUtils.dip2px(context,1),LayoutParams.MATCH_PARENT);
        rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        rightDivider.setLayoutParams(rightParams);
        rightDivider.setBackgroundResource(mDividerColor);

        topDivider=new View(context);
        LayoutParams topParams=new LayoutParams(LayoutParams.MATCH_PARENT,ScreenUtils.dip2px(context,1));
        topDivider.setLayoutParams(topParams);
        topDivider.setBackgroundResource(mDividerColor);

        bottomDivider=new View(context);
        LayoutParams bottomParams=new LayoutParams(LayoutParams.MATCH_PARENT,ScreenUtils.dip2px(context,1));
        bottomParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        bottomDivider.setLayoutParams(bottomParams);
        bottomDivider.setBackgroundResource(mDividerColor);

        addView(leftDivider);
        addView(rightDivider);
        addView(topDivider);
        addView(bottomDivider);

        leftDivider.setVisibility(INVISIBLE);
        topDivider.setVisibility(INVISIBLE);
        rightDivider.setVisibility(INVISIBLE);
        bottomDivider.setVisibility(INVISIBLE);
    }

    public void setStyle(int type){
        switch (type){
            case LEFT_TOP:
                leftDivider.setVisibility(VISIBLE);
                topDivider.setVisibility(VISIBLE);
                break;
            case LEFT_TOP_RIGHT:
                leftDivider.setVisibility(VISIBLE);
                topDivider.setVisibility(VISIBLE);
                rightDivider.setVisibility(VISIBLE);
                break;
            case TOP_RIGHT:
                topDivider.setVisibility(VISIBLE);
                rightDivider.setVisibility(VISIBLE);
                break;
            case RIGHT:
                rightDivider.setVisibility(VISIBLE);
                break;
            case BOTTOM:
                bottomDivider.setVisibility(VISIBLE);
                break;
//            case LEFT_TOP_RIGHT_BOTTOM:
//                leftDivider.setVisibility(VISIBLE);
//                topDivider.setVisibility(VISIBLE);
//                rightDivider.setVisibility(VISIBLE);
//                bottomDivider.setVisibility(VISIBLE);
//                break;
            case LEFT:
                leftDivider.setVisibility(VISIBLE);
                break;
            case LAST_LEFT:
                RelativeLayout.LayoutParams rightParams=new RelativeLayout.LayoutParams(ScreenUtils.dip2px(context,2),LayoutParams.MATCH_PARENT);
                rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                rightDivider.setLayoutParams(rightParams);
                rightDivider.setBackgroundResource(mDividerColor);
                break;
        }
    }

    public void clearDivider(){
        leftDivider.setVisibility(INVISIBLE);
        topDivider.setVisibility(INVISIBLE);
        rightDivider.setVisibility(INVISIBLE);
        bottomDivider.setVisibility(INVISIBLE);
    }

    public void setChildViewGone(){
//        ChildView.setVisibility(INVISIBLE);
        rightDivider.setVisibility(INVISIBLE);
        bottomDivider.setVisibility(INVISIBLE);
    }

    public void setChildViewGoneT(){
//        ChildView.setVisibility(INVISIBLE);
        leftDivider.setVisibility(INVISIBLE);
        rightDivider.setVisibility(INVISIBLE);
        bottomDivider.setVisibility(INVISIBLE);
    }
}
